package com.second.task;

/**
 * 本类用来演示: 异步的任务调度
 *
 * @author: success
 * @date: 2022/4/27 10:07 上午
 */

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import com.second.consts.RabbitConst;

import java.util.Map;

@Component
public class OrdTask {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    //多线程,springboot异步调度 => 异步编程中的几种不同形式而已.
    //一个线程是可以去完成多个任务的.
    @Async
    public void sendOrdToRbm(Map<String, Object> args) {
        //传入到一个正常的30min订单队列中去的.
        rabbitTemplate.convertAndSend(RabbitConst.ORD_DIRECT_EX, RabbitConst.ORD_QUEUE_RK, args, msg -> {
            msg.getMessageProperties().setExpiration("1200000");//20min1200000
            return msg;
        });
    }
}
